package jobs.rewrite;

import javax.servlet.ServletContext;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
import org.ocpsoft.rewrite.servlet.config.rule.Join;

/**
 * Clase que nos permite re-escribir las URL's de la aplicación
 *
 * @author Paul Tamayo
 */
public class URLRewriteProvider extends HttpConfigurationProvider {

    private final static String SITE_PATH = "/admin/jobs/";
    private final static String ADMIN_PATH = "/admin/";

    @Override
    public Configuration getConfiguration(ServletContext t) {
        ConfigurationBuilder builder = ConfigurationBuilder.begin();

        builder.addRule(Join.path("/").to("/index.xhtml"));
        builder.addRule(Join.path(ADMIN_PATH + "grado").to(SITE_PATH + "grades.xhtml"));
        builder.addRule(Join.path(ADMIN_PATH + "niveles").to(SITE_PATH + "levels.xhtml"));
        builder.addRule(Join.path(ADMIN_PATH + "grupo-ocupacionales").to(SITE_PATH + "occupationalgroup.xhtml"));
        builder.addRule(Join.path(ADMIN_PATH + "roles").to(SITE_PATH + "roles.xhtml"));
        builder.addRule(Join.path(ADMIN_PATH + "unidades").to(SITE_PATH + "units.xhtml"));

        return builder;
    }

    @Override
    public int priority() {
        return 10;
    }
}
